<!-- 我的分组 -->

<template>
  <WebForm path="map" class="MapLabel-MyGroup">
    <div class="MapLabel-MyGroup-title">
      <span>标签分组</span>
    </div>

    <FormInput :one="map_param" tip="分组名称" bind="keyword" medium noLabel />

    <EasyScroll>
      <div class="minFull" @mousedown.self="map_setOne" @contextmenu.prevent="CORE.doNothing">
        <div
          v-for="item in groupList"
          :key="item.id"
          class="inFlexCC flexCol"
          :style="item.style"
          @mousedown.prevent="mouseDown($event, item)"
          @contextmenu.prevent="CORE.doNothing"
        >
          <div>{{ item.nameTop || '-' }}</div>
          <div v-if="item.nameBottom">{{ item.nameBottom }}</div>
        </div>

        <el-empty v-if="!groupList.length" description="暂无分组" />
      </div>
    </EasyScroll>
  </WebForm>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'MyGroup',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb('map', 'map_'), CORE.mixInfo('map', 'map_'), CORE.mixSelect('group', 'group_')],

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: {
    /**
     * 分组列表
     */
    groupList() {
      const { map_param: { keyword }, group_select } = this
      const groupList = group_select.filter((item) => item.labelGroupName.includes(keyword))

      return groupList.map(item => {
        const { labelGroupName: name, backgroundColor } = item
        const nameTop = name.length < 4 ? name : name.length === 4 ? name.slice(0, 2) : name.slice(0, 3)
        const nameBottom = name.length < 4 ? '' : name.length === 4 ? name.slice(2) : name.slice(3)
        return { ...item, nameTop, nameBottom, style: { '--MyColor': backgroundColor } }
      })
    },
  },

  /**
   * 监听属性 (深度 deep 首次 immediate)
   */
  watch: {
    /**
     * 监听选中设备
     */
    chosen(chosen) {
      this.toClick(chosen)
    },
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 点击每项
     */
    mouseDown({ button }, { id, labelGroupName, labelGroupCode, typeLabel, typeValue }) {
      if (button !== 0) return this.map_setOne() // 非左键

      const { map_param: { areaId, areaMapId } } = this

      // 开始打点
      this.map_setOne({
        areaMapId,
        areaId,
        areaName: CORE.REGION.NAME[areaId],
        labelGroupId: id,
        labelGroupName,
        labelGroupCode,
        typeLabel,
        typeValue,
      })
    },
  },
}
</script>

<style lang="scss">
@import './index.scss';
</style>
